//跨页面获取参数
function parse(search) {
    //从第二个字符开始截取   ，获取到第二个开始后面所有的字符
    var str = search.substring(1);
    var result = {};
    //分割字符串  -->产生字符串数组
    var strs = str.split("&");
    //遍历数组中的每一个元素
    var result = strs[0].split("=");
    return result[1];
    /* var params = result[1];
     strs.forEach(function(v){
     //伪代码：v="age=18"
     var keyvalue=v.split("=");
     var name=keyvalue[0];
     var value=keyvalue[1];
     result[name]=value;
     })
     return result;
     */
}

$(function() {
    var search = location.search;
    var param = parse(search);
    var monthId = -1;
    var themeId = -1;
    var dayId = -1;
    var currentPage = 1;

    if (param){
        if (param > 21) {
            themeId = param;
            $(".theme a").removeClass('on');
            $('.theme a[data-themeId=' + param + ']').addClass('on');
        } else {
            monthId = param;
            $(".month a[data-monthId='-1']").removeClass("on");
            $('.month a[data-monthId=' + param + ']').addClass("on");
        }
    }

    $.get("/destination/listByThemeIds",{
        monthId: monthId,
        themeId: themeId,
        dayId: dayId,
        currentPage: currentPage
    },function (data) {
        $(".row-list .clearfix").html(data);
    })


    $(".filter-nav a").on("click", function () {
        var tempId = $(this).data("monthid");
        if (tempId) {
            monthId = tempId;
            $(".date a").removeClass("on");
        }
        tempId = $(this).data("themeid");
        console.log(tempId);
        if (tempId) {
            themeId = tempId;
            $(".theme a").removeClass('on');
        }
        tempId = $(this).data("dayid");
        console.log(tempId);
        if (tempId) {
            dayId = tempId;
            $(".day a").removeClass('on');
        }
        $(this).addClass("on");
        $(".row-list .clearfix").html("");
        $.get("/destination/listByThemeIds", {
            monthId: monthId,
            themeId: themeId,
            dayId: dayId,
            currentPage: currentPage
        }, function (data) {
            if (data) {
                $(".row-list .clearfix").append(data);
            }
        });
    })

});